<!--用户发言链接-->
<script setup>
import {ThreadUtils} from "@/assets/js/ThreadUtils";
import {setupMapState} from "@/assets/js/vuexUtils";
import {routeNames} from "@/router";
import {toRefs} from "vue";
import NgaRouterLink from "@/components/common/link/NgaRouterLink.vue";

const props = defineProps({
  userId: {type: Number, required: true},
  forumId: {type: Number},
  page: {type: Number},
  // 搜索精华帖
  recommend: {type: Boolean},
  // 搜索回复
  searchReply: {type: Boolean},
  bracket: Boolean,
})

const {currentUid} = setupMapState("Account", ['currentUid']);
const {data} = toRefs(props)

const getRoute = ({userId, forumId, page, recommend, searchReply}) => {
  const name = searchReply ? routeNames.user.replies : routeNames.user.topic
  const query = {account: currentUid.value};
  pushParams(query, searchReply, recommend, forumId, page);
  return {name, params: {id: userId}, query}
}

function pushParams(query, searchReply, recommend, forumId, page) {
  if (!searchReply && recommend) query.recommend = 1
  if (forumId) query.fid = forumId
  if (page) query.page = page
}

const getUrl = ({userId, forumId, page, recommend, searchReply}) => {
  const name = searchReply ? routeNames.user.replies : routeNames.user.topic
  const query = {id: userId}
  pushParams(query, searchReply, recommend, forumId, page);
  return ThreadUtils.buildOfficialUrl(name, query);
}

</script>

<template>
  <span>
    <el-tooltip placement="top">
      <nga-router-link :bracket="bracket" :route="getRoute(props) ">
        <slot></slot>
      </nga-router-link>
      <template #content>
        <el-link v-if="userId" :href="getUrl(props)" target="_blank" type="primary">官方地址</el-link>
      </template>
    </el-tooltip>
  </span>
</template>

<style scoped>

</style>